var express = require('express');
var router = express.Router();
const mysqlExec=require('../db/dbMysql');
let {Msg,curPath}=require('../tools/msg.js');

//首页，轮播图的接口
router.get('/banner',async function(req,res){
  let sql=`select concat('${curPath}banners/',image_src)as image_src,title from e_banners`;
  let [err,arr]= await mysqlExec(sql);
  if(err){
    res.send(Msg(200,'轮播图查询成功',arr))
  }else{
    res.send(Msg(500,'轮播图查询失败'))
  }
})

//首页课程接口
router.get('/course',async (req,res)=>{
  let {tid=1,limits=8}=req.query;
  let sql = `select cid,title,price,concat('${curPath}course/',image_src) as image_src,type_name,area_name,subject_name from e_course where type=${tid} limit ${limits}`;
  let [err,arr]=await mysqlExec(sql);
  if(err){
    res.send(Msg(200,'查询成功',arr));
  }else{
    res.send(Msg(500,'查询失败'))
  }

})

module.exports = router;
